********************************************************************************
********************************************************************************
* Title: 		session_time
* Project:		Stress, Ethnicity, and Prosocial Behavior
* Author:		Moritz Poll (moritz.poll@brown.edu)
* PIs:			Johannes Haushofer, Sara Lowes, Abednego Musau, David Ndetei, 
*				Nathan Nunn, Moritz Poll, Nancy Qian
* Purpose:		Session Time Analysis and Visualization
********************************************************************************
********************************************************************************
noisily dis as input "Start: Session time analysis"

********************************************************************************
*************************** Time Sheet Visualization ***************************
********************************************************************************
use  "$cleandata_dir/HIO_for_analysis_session.dta", clear
keep session ts_*_pill ts_taskorder

ds ts_pill_pill - ts_end_time_pill
local postpill `r(varlist)'
ds ts_welcome_pill - ts_pill_pill
foreach var in `r(varlist)' {
	local prepill `var' `prepill'
}
graph hbar `prepill' `postpill', over(ts_taskorder, relabel(1 "DG First" 2 "TG First") label( angle(90))) ///
	bargap(-100) ylabel(-240(60)120) yline(0, lcolor(black)) ytitle("Minutes relative to pill") $bar_design xsize(8) ///
	legend(cols(4) colfirst size(small) order(14 "Registration" 13 "Consent" 12 "Medical Screening" 11 "Moving to laboratory" 10 "Lab Welcome" 9 "Demographics" 8 "Primer Profile" 7 "General Instructions" 6 "Game 1 Instructions" 5 "Game 2 Instructions" 4 "Game 3 Instructions" 3 "Game 4 Instructions" 2 "Salivette 1" 1 "Pill" 15 "Slider Instructions" 16 "Vital Signs" 17 "Pause" 18 "Re-Primer Profile" 19 "Salivette 2" 20 "Game 1" 21 "Salivette 3" 22 "Game 2" 23 "Salivette 4" 24 "Game 3" 25 "Salivette 5" 26 "Game 4" 27 "Salivette 6" 28 "Social Proximity" 29 "Pill Guess" 30 "Demand Treatment" 31 "More Demographics" 32 "Debrief"))
graph export "$figures_dir/timesheet.pdf", replace

noisily dis as input "End: Session time analysis"
